<?php 
    $url = new Url();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);
?>
<script type="text/javascript">
    function ajaxSaveContent(type){
        var content = "";
        var content_id = "";
        id = "";
        $("input[name=content_"+type+"]").each(function(){
            content += parseInt($(this).attr("id")) + ":" + rtrim(this.value,",") + ";";
            if(rtrim(this.value,",") !=""){
                content_id += rtrim(this.value,",") + ",";
            }
        });
        var strUrl = "<?=$url->createUrl("emailMarketing/ajaxSaveContent") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                content:content,
                content_id:content_id,
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            },
            beforeSend:function(){
                $("#button_save_"+type).attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save_"+type).removeAttr("disabled"); 
            }            
        });
    }
    function ajaxSaveLinkFooter(){
        var strUrl = "<?=$url->createUrl("emailMarketing/ajaxSaveLinkFooter") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                position:$("#position").val(),
                title:$("#title").val(),
                url:$("#url").val(),
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm mới thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }            
        });
    }
    function ajaxQuickUpdate(id){
        var strUrl = "<?=$url->createUrl("emailMarketing/ajaxQuickUpdate") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                position:$("#position_"+id).val(),
                title:$("#title_"+id).val(),
                url:$("#url_"+id).val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?=$url->createUrl("emailMarketing/ajaxDelete") ?>";
        if(confirm('Bạn có chắc chắn muốn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <div class="col49">
            <div class="box-bor">
                <p align="center" style="margin-bottom:20px;font-size:14px"><strong>Sản Phẩm Mới</strong></p>
                <ul class="form1 bottom20">
                    <li class="clearfix"><label><strong>Game online </strong>:</label>
                        <div class="filltext">
                            <input name="content_new" id="<?php echo $data[1]["id"]?>" type="text" style="width:330px" value="<?php echo $data[1]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Game offline</strong>:</label>
                        <div class="filltext">
                            <input name="content_new" id="<?php echo $data[2]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[2]["content_id"]?>"> 
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Video </strong>:</label>
                        <div class="filltext">
                            <input name="content_new" id="<?php echo $data[3]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[3]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Ảnh </strong>:</label>
                        <div class="filltext">
                            <input name="content_new" id="<?php echo $data[4]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[4]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label>&nbsp;</label>
                        <div class="filltext">
                            <input type="button" id="button_save_new" onclick="ajaxSaveContent('new')" value=" Lưu thay đổi " class="btn-bigblue"> 
                        </div>
                    </li>

                </ul>
                <p><em>Nhập ID sản phẩm vào ô, mỗi sản phẩm cách nhau bởi dấu(,).Tổng sản phẩm không vượt qua 5</em></p>
            </div>
        </div>
        <div class="col2">&nbsp;</div>
        <div class="col49">
            <div class="box-bor">
                <p align="center" style="margin-bottom:20px;font-size:14px"><strong>Sản Phẩm HOT</strong></p>
                <ul class="form1 bottom20">
                    <li class="clearfix"><label><strong>Game online </strong>:</label>
                        <div class="filltext">
                            <input name="content_hot" id="<?php echo $data[5]["id"]?>" type="text" style="width:330px" value="<?php echo $data[5]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Game offline</strong>:</label>
                        <div class="filltext">
                            <input name="content_hot" id="<?php echo $data[6]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[6]["content_id"]?>"> 
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Video </strong>:</label>
                        <div class="filltext">
                            <input name="content_hot" id="<?php echo $data[7]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[7]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label><strong>Ảnh </strong>:</label>
                        <div class="filltext">
                            <input name="content_hot" id="<?php echo $data[8]["id"]?>" type="text" style="width:330px;" value="<?php echo $data[8]["content_id"]?>">
                        </div>
                    </li>
                    <li class="clearfix"><label>&nbsp;</label>
                        <div class="filltext">
                            <input type="button" id="button_save_hot" onclick="ajaxSaveContent('hot')" value=" Lưu thay đổi " class="btn-bigblue"> 
                        </div>
                    </li>

                </ul>
                <p><em>Nhập ID sản phẩm vào ô, mỗi sản phẩm cách nhau bởi dấu(,).Tổng sản phẩm không vượt qua 5</em></p>
            </div>
        </div>
    </div>
    <div class="title-blue">
        <h3><strong>Thông tin thêm</strong></h3>
    </div>
    <div class="box">
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table border="0" width="100%" cellspacing="0" cellpadding="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="10%"><strong>Thứ tự</strong></td>
                        <td width="32%"><strong>Tên hiển thị</strong></td>
                        <td width="48%"><strong>Link</strong></td>
                        <td width="12%"><strong>Quản trị </strong></td>
                    </tr>
                    <tr>
                        <td><input type="text" id="position" style="width:50%"></td>
                        <td><input type="text" id="title" style="width:90%"></td>
                        <td><input type="text" id="url" style="width:90%"></td>
                        <td><input id="button_save" onclick="ajaxSaveLinkFooter()" type="button" class="btn-gray" value="Thêm "></td>
                    </tr>
                    <?php foreach($data_footer as $key=>$value){?>
                        <tr>
                            <td><input type="text" id="position_<?php echo $value["id"]?>" value="<?php echo intval($value["position"])?>" style="width:50%"></td>
                            <td><input type="text" id="title_<?php echo $value["id"]?>" value="<?php echo $value["title"]?>" style="width:90%"></td>
                            <td><input type="text" id="url_<?php echo $value["id"]?>" value="<?php echo $value["url"]?>" style="width:90%"></td>
                            <td>
                                <a href="javascript:void(0)" onclick="ajaxQuickUpdate('<?php echo $value["id"];?>')">  Lưu</a>  | 
                                <a href="javascript:void(0)" onclick="ajaxDelete('<?php echo $value["id"];?>')">  Xóa</a>
                            </td>
                        </tr>
                        <?php }?>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fl">&nbsp;</div>
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
    </div>
</div>